﻿package com.orlleite.effects
{
	import caurina.transitions.Tweener;
	import flash.display.DisplayObject;
	import gs.TweenMax;
	
	/**
	 * ...
	 * @author Orlando Leite
	 */
	public class SimpleEffects 
	{
		
		public function SimpleEffects() 
		{
			
		}
		
		public static function alphaEffect( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tween:TweenMax = new TweenMax( obj, time, { alpha:params.direction ? 1 : 0, delay:delay + ( 0.01 * charAt ) } );
		}
		
		public static function randomAlphaEffect( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tween:TweenMax = new TweenMax( obj, time, { alpha:params.direction ? 1 : 0, delay:delay + ( Math.random() * time / 2 ) } );
		}
		
		public static function blurEffect( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var nextAlpha:Number;
			var nextBlur:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				nextBlur = 0;
			}
			else
			{
				nextAlpha = 0;
				nextBlur = 20;
			}
			
			var preBlurX:Number = params.blurX ? params.blurX : params.direction ? 20 : 0;
			var preBlurY:Number = params.blurY ? params.blurY : params.direction ? 20 : 0;
			
			var preTween:TweenMax = new TweenMax( obj, 0, { blurFilter:{ blurX:preBlurX, blurY:preBlurY, quality:2 } } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( 0.05 * charAt ), blurFilter:{ blurX:nextBlur, blurY:nextBlur, quality:2 } } );
		}
		
		public static function randomBlurEffect( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var nextAlpha:Number;
			var nextBlur:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				nextBlur = 0;
			}
			else
			{
				nextAlpha = 0;
				nextBlur = 20;
			}
			
			var preBlurX:Number = params.blurX ? params.blurX : params.direction ? 20 : 0;
			var preBlurY:Number = params.blurY ? params.blurY : params.direction ? 20 : 0;
			
			var preTween:TweenMax = new TweenMax( obj, 0, { blurFilter:{ blurX:preBlurX, blurY:preBlurY, quality:2 } } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( Math.random() * time / 2 ), blurFilter: { blurX:nextBlur, blurY:nextBlur, quality:2 } } );
		}
		
		public static function moveTo( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tempX:Number;
			var tempY:Number;
			var fromX:Number;
			var fromY:Number;
			var nextAlpha:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				fromX = obj.x + ( params.x ? params.x : 0 );
				fromY = obj.y + ( params.y ? params.y : 0 );
				tempX = obj.x;
				tempY = obj.y;
			}
			else
			{
				nextAlpha = 0;
				tempX = obj.x + ( params.x ? params.x : 0 );
				tempY = obj.y + ( params.y ? params.y : 0 );
				fromX = obj.x;
				fromY = obj.y;
			}
			
			var preTween:TweenMax = new TweenMax( obj, 0, { x:fromX, y:fromY } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( 0.05 * charAt ), x:tempX, y:tempY } );
		}
		
		public static function blurMoveTo( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tempX:Number;
			var tempY:Number;
			var fromX:Number;
			var fromY:Number;
			var nextBlur:Number;
			var nextAlpha:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				nextBlur = 0;
				fromX = obj.x + ( params.x ? params.x : 0 );
				fromY = obj.y + ( params.y ? params.y : 0 );
				tempX = obj.x;
				tempY = obj.y;
			}
			else
			{
				nextAlpha = 0;
				nextBlur = 20;
				tempX = obj.x + ( params.x ? params.x : 0 );
				tempY = obj.y + ( params.y ? params.y : 0 );
				fromX = obj.x;
				fromY = obj.y;
			}
			
			var preBlurX:Number = params.blurX ? params.blurX : params.direction ? 20 : 0;
			var preBlurY:Number = params.blurY ? params.blurY : params.direction ? 20 : 0;
			
			var preTween:TweenMax = new TweenMax( obj, 0, { x:fromX, y:fromY, blurFilter:{ blurX:preBlurX, blurY:preBlurY, quality:2 } } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( 0.05 * charAt ), x:tempX, y:tempY, blurFilter: { blurX:nextBlur, blurY:nextBlur, quality:2 } } );
		}
		
		public static function randomMoveTo( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tempX:Number;
			var tempY:Number;
			var fromX:Number;
			var fromY:Number;
			var nextAlpha:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				fromX = obj.x + ( Math.random() * 2 - 1 ) * 20;
				fromY = obj.y + ( Math.random() * 2 - 1 ) * 20;
				tempX = obj.x;
				tempY = obj.y;
			}
			else
			{
				nextAlpha = 0;
				tempX = obj.x + ( Math.random() * 2 - 1 ) * 20;
				tempY = obj.y + ( Math.random() * 2 - 1 ) * 20;
				fromX = obj.x;
				fromY = obj.y;
			}
			
			var preTween:TweenMax = new TweenMax( obj, 0, { x:fromX, y:fromY } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( Math.random() * time / 2 ), x:tempX, y:tempY } );
		}
		
		public static function randomBlurMoveTo( obj:DisplayObject, charAt:int, time:Number, delay:Number, params:Object ):void
		{
			var tempX:Number;
			var tempY:Number;
			var fromX:Number;
			var fromY:Number;
			var nextBlur:Number;
			var nextAlpha:Number;
			
			if ( params.direction )
			{
				nextAlpha = 1;
				nextBlur = 0;
				fromX = obj.x + ( Math.random() * 2 - 1 ) * 20;
				fromY = obj.y + ( Math.random() * 2 - 1 ) * 20;
				tempX = obj.x;
				tempY = obj.y;
			}
			else
			{
				nextAlpha = 0;
				nextBlur = 20;
				tempX = obj.x + ( Math.random() * 2 - 1 ) * 20;
				tempY = obj.y + ( Math.random() * 2 - 1 ) * 20;
				fromX = obj.x;
				fromY = obj.y;
			}
			
			var preBlurX:Number = params.blurX ? params.blurX : params.direction ? 20 : 0;
			var preBlurY:Number = params.blurY ? params.blurY : params.direction ? 20 : 0;
			
			var preTween:TweenMax = new TweenMax( obj, 0, { x:fromX, y:fromY, blurFilter:{ blurX:preBlurX, blurY:preBlurY, quality:2 } } );
			var tween:TweenMax = new TweenMax( obj, time, { alpha:nextAlpha, delay:delay + ( Math.random() * time / 2 ), x:tempX, y:tempY, blurFilter: { blurX:nextBlur, blurY:nextBlur, quality:2 } } );
		}
		
	}
	
}